{{if false}}<script>{{/if}}
{{$controller = $smarty.const.CCTRL}}
{{$token = $smarty.const.TOKEN}}
{{$display=0}}
includecss("{{base_url()}}syslib/jqwidgets/styles/jqx.base.css");
includecss("{{base_url()}}syslib/jqwidgets/styles/jqx.classic.css");
includejs("{{base_url()}}syslib/jqwidgets/globalization/jquery.global.js");
includejs("{{base_url()}}syslib/jqwidgets/jqx-all.js");
//include("{{base_url()}}syslib/jqwidgets/gettheme.js");
{{include file="../00_base/colmod_advanced.tpl"}}
var myjqxGrid;
var myGrid=$("#jqxGrid");
$(document).ready(function(){
    initSetting();
    myjqxGrid= (function () {
        var theme = 'classic';
        var source ={
            datatype: "json",
            type        :   "POST",
            datafields  : adatafiels,
            url         : '{{base_url()}}backend/{{$controller}}/binding/{{if isset($type)}}{{$type}}{{/if}}',
            filter      : function(){ 
                myGrid.jqxGrid('updatebounddata', 'filter');
                
            },
            sort        : function(){ 
                myGrid.jqxGrid('updatebounddata');
                
            },
            root        : 'Rows',
            beforeprocessing: function(data){		
                    source.totalrecords = data[0].TotalRows;					
            }
        };	
        var dataadapter = new $.jqx.dataAdapter(source, {
            loadError: function(xhr, status, error){
                tipMessage("<b>Status</b>:"+xhr.status+"<br/><b>ThrownError</b>:"+error+"<br/>");
            }
        });
        if(typeof handleEvents == 'function') { 
            handleEvents();
        }
        var gridconfig={
            width:'100%',
            //autoheight: true,
            rowsheight: 24,
            source: dataadapter,
            theme: theme,
            //sortable: true,
            editable:true,
            ready: function () {

            },
            rendergridrows: function(obj)
            {
                return obj.data;    
            },
            //groupable:true,
            //filterable: true,
            //autoshowfiltericon: true,
            //showfilterrow: true,
            editmode:'dblclick',
            selectionmode:'multiplecellsextended',
            height:($(document).height() - 200)>500?($(document).height() - 200):500,
            virtualmode: true,
            columns: acolumns
        };
        //Adding event listeners
        function _addEventListeners() {

        };
        //Creating all page elements which are jqxWidgets
        function _createElements() {

        };
        function _createGrid(){
            try{
                myGrid.jqxGrid(gridconfig);
                //handleEvent_jqxGrid(myGrid);
            }catch(e){ tipMessage(e.message); }
        }
        return {
            Init:function(){
                _createGrid();
                
            },
            Setting:function(){
                
            },
            Refresh:function(){
                myGrid.jqxGrid('updatebounddata');
                
            },
            ShowColumn:function(col){
                console.log("Hide column: "+col+" ↵ Call");
                myGrid.jqxGrid('hidecolumn', col);
                myjqxGrid.DisplayColumnChange(col,1);
            },
            HideColumn:function(col){
                console.log("Show column: "+col+" ↵ Call");
                myGrid.jqxGrid('showcolumn', col);
                myjqxGrid.DisplayColumnChange(col,0);
            }
        }
    } ());
    myjqxGrid.Init();
    //console.log(acolumns);
});
function gridSetting(){
    var tit="<img class='pa t7 l8 ico16'src='{{base_url()}}syslib/sysimages/16/option.gif'/><font class='pl20'>Settings !</font>";
    ShowDialogMessage($("#window-sOpt"),tit);
}
function gridRefresh(){
    myjqxGrid.Refresh();
}
function toogleEvent(){
    $(".btnseparator.hidden,.events.hidden").toggle();
    $(".events span.show").toggleClass("hide");
}